package com.tour.service.impl;

import com.tour.bean.Hotel;
import com.tour.bean.ReturnT;
import com.tour.dao.HotelMapper;
import com.tour.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * hotel
 * @author
 * @date 2020/03/16
 */
@Service
public class HotelServiceImpl implements HotelService {

    @Autowired
    private HotelMapper hotelMapper;


    @Override
    public ReturnT<String> insert(Hotel hotel) {

        // valid
        if (hotel == null) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, "必要参数缺失");
        }

        hotelMapper.insert(hotel);
        return ReturnT.SUCCESS;
    }


    @Override
    public ReturnT<String> delete(int id) {
        int ret = hotelMapper.delete(id);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public ReturnT<String> update(Hotel hotel) {
        int ret = hotelMapper.update(hotel);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public Hotel load(int id) {
        return hotelMapper.load(id);
    }


    @Override
    public Map<String,Object> pageList(int offset, int pagesize,String title,String address) {
        Map<String,Object> param=new HashMap<>();
        param.put("offset",offset);
        param.put("pageSize",pagesize);
        param.put("title",title);
        param.put("address",address);
        List<Hotel> pageList = hotelMapper.pageList(param);
        int totalCount = hotelMapper.pageListCount(param);

        // result
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);

        return result;
    }

}

